package com.bookcode.service;


import com.bookcode.dao.CourseRepository;
import com.bookcode.entity.Course;
import com.bookcode.entity.CourseStudent;
import com.bookcode.entity.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

@Service
@Transactional
public class CourseService {

    @Autowired
    CourseRepository courseRepository;
    //通过课程id 查询课程
    public Course findCourseById(Long id){
        return courseRepository.findById(id).get();
    }
    public Course findCourseByCourseId(String  courseId){
        return courseRepository.findCourseByCourseId(courseId);
    }
    //通过课程名查课程
    public Course findCourseByName(String name){
        return courseRepository.findCourseByName(name);
    }
    //查询所有课程
    public List<Course> findAll(){
        return courseRepository.findAll();
    }
    //保存课程
    public void save(Course course){
        courseRepository.save(course);
    }
    //通过课程号删除课程
    public void deleteCourseById(String course_id){
        courseRepository.deleteCourseById(course_id);
    }
}
